require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#candidate",
    data:{
        type:"",
        title:"全部职位",
        stateName:"全部状态",
        loadFlag:false,
        list:{
            loginUid:userInfo.id,
            // loginUid:1,
            recruitId:"",
            pageNumber:1,
            state:""
        },
        recruitList:{},//列表
        recruitList1:[],
        recruitList2:[],
        isScreen:"",
        recruitInfo:{},//职位列表

        stateList:[
            // {"stateName":"全部状态","state":""},
            {"stateName":"待筛选","state":"1"},
            {"stateName":"待沟通","state":"2"},
            {"stateName":"不匹配","state":"3"}],//状态列表
        name:""
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.type=this.searchObject&&this.searchObject.type;
        if(this.type==3){
            this.name="候选人"
        }else{
            this.name="人才收藏"
        }
        if(this.searchObject&&this.searchObject.recruitId){
            this.list.recruitId=this.searchObject&&this.searchObject.recruitId;
            this.title=decodeURI(this.searchObject&&this.searchObject.title);
        }
        this.myRecruit();
        this.myCandidate();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //tab切换
        getIsScreen:function(num){
           this.isScreen=num;
           console.log(num)
        },
        //我的应聘
        myRecruit:function(){
            var that=this;
            var data={
                loginUid:that.list.loginUid
            };
            this.ajax({url:"/happyi/myRecruit",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.recruitInfo=b.json.data.recruits;
                    // that.list.title=that.applyInfo.functionsName;

                }else{
                    vm.$refs.prompt.toast("获取信息失败！");
                }
            });

        },
        getSelect:function(type,item){
            var that=this;
            window.scrollTo(0,0);
            that.list.pageNumber=1;
            that.recruitList={};
            that.recruitList1=[];
            that.recruitList2=[];
            if(type==1){
                if(item){
                    that.list.recruitId=item.recruitId;
                    that.title=item.title;
                }else{
                    that.list.recruitId="";
                    that.title="全部职位";
                }
            }else if(type==2){
                if(item){
                    that.list.state=item.state;
                    that.stateName=item.stateName;
                }else{
                    that.list.state="";
                    that.stateName="全部状态";
                }
            }
            that.getIsScreen();
            that.myCandidate();
        },
        //候选人列表
        myCandidate:function(){
            var that=this;
            this.ajax({url:"/happyi/myCandidate",data:that.list,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.recruitList=b.json.data;
                    that.recruitList1=that.recruitList.list;
                    if(that.recruitList.pageNumber>1){
                        if(that.recruitList.list.length>0) {
                            that.recruitList2 = that.recruitList2.concat(b.json.data.list);
                        }
                    }else{
                        that.recruitList2= that.recruitList1;
                    }
                    vm.loadFlag=false;
                }else{
                    that.recruitList={};
                    that.recruitList1=[];
                    that.recruitList2=[];
                    vm.$refs.prompt.toast("获取列表失败！")
                }
            });
        },
        getNext:function(item){
            console.log(item)
            location.href="/happyi/resumePreview?type=3&resumeId="+item.resumeId+"&loginUid="+this.list.loginUid;
        }
    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    var loadFlag = vm.recruitList.lastPage;
    if(loadFlag!=undefined){
        //监听事件内容
        if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
            //当滚动条到底时,这里是触发内容
            if(!loadFlag){
                vm.loadFlag=true;
                vm.list.pageNumber++;
                vm.myCandidate();
            }else{
                // console.log("11111");
                vm.$refs.prompt.toast("没有更多了！")
            }
        }
    }

};